/**
 * @Description:
 * @Author: saqqdy
 * @LastEditors: saqqdy
 * @Date: 2021-07-18 00:39:35
 * @LastEditTime: 2021-07-18 12:54:09
 */
import path from 'path'

import { aliasItems, devServerUrl, externalItems } from './config'
import entry from './entry'
import optimization from './optimization'
import * as plugins from './plugins'
import * as rules from './rules'
import { isDevServer, isProd } from './utils/env'
import { arrayFilterEmpty } from './utils/helpers'

export default {
    context: __dirname,
    target: isDevServer ? 'web' : ['web', 'es5'],
    mode: isProd ? 'production' : 'development',
    entry,
    output: {
        path: path.join(__dirname, '../dist'),
        publicPath: isDevServer ? devServerUrl : './',
        filename: isDevServer ? '[name].[fullhash].js' : '[name].[contenthash].js'
    },
    module: {
        rules: arrayFilterEmpty([rules.javascriptRule, rules.typescriptRule, rules.htmlRule, rules.imagesRule, rules.fontsRule, rules.cssRule, ...rules.lessRules, ...rules.sassRules, ...rules.svgRules])
    },
    plugins: arrayFilterEmpty([plugins.htmlWebpackPlugin, plugins.providePlugin, plugins.definePlugin, plugins.forkTsCheckerWebpackPlugin, plugins.esLintPlugin, plugins.copyPlugin, plugins.antdDayjsPlugin]),
    resolve: {
        alias: aliasItems,
        extensions: ['.tsx', '.ts', '.js', '.jsx']
    },
    optimization,
    externals: externalItems
}
